A Script of Plus/Minus Time

 

A script of Plus/Minus Time

 

@TimePlusMin(year,mon,day,hour,min)      Add 1 minute for the given time (the value of argument).

@TimePlusHour(year,mon,day,hour)         Add 1 hour for the given time (the value of argument).

@TimePlusDay(year,mon,day)                Add 1 day for the given time (the value of argument).

@TimePlusMon(year,mon)                    Add 1 Month for the given time (the value of argument).

@TimeMinusMin(year,mon,day,hour,min)     Subtract 1 minute for the given time (the value of argument).

@TimeMinusHour(year,mon,day,hour)        Subtract 1 hour for the given time (the value of argument).

@TimeMinusDay(year,mon,day)              Subtract 1 Day for the given time (the value of argument).

@TimeMinusMon(year,mon)                  Subtract 1 Month for the given time (the value of argument).

 

By using above scripts, the time that user wants to set is specified.

 

Example)

 

1)     View report at a time specified by the user in a localmain

 

For this script, the @ReportSetTime() and @ReportView() should be used.

 

 

Like a screen of setting time above,

 

1)-1  Register YEAR, MON and DAY (tag name is user-defined) as memory tags in analog input tag.

1)-2  Display the tags on screen, and write script using script button.

(The script button simply runs adding or subtracting 1 day)

 

Write a script minus 1 day within the script button ('D-' button).

 

 

@TimeMinusDay($YEAR,$MON,$DAY);

 

It only needs to add one line of script as above.

 

Write a script plus 1 day within the script button ('D-' button).

 

@TimePlusDay($YEAR,$MON,$DAY);

 

It only needs to add one line of script as above.

 

1)-3  Add a script button to show report.

 

Write the script to the 'View Report' button as follows.

 

 

@ReportSetTime($YEAR, $MON, $DAY);

@ReportView("Report1.rptx");      // Report1.rptx is the name of the report file that user created.

 

Using it as above, you can view the report on the date you specify (on the localmain).

 

 

2)     View past data at a time specified by the user in the localmain.

 

To perform this, the following scripts must be used.

 

@DataGetAiMin("Tag-name",int Data-Type,year,mon,day,hour,min);

@DataGetAiHour("Tag-name",int Data-Type,year,mon,day,hour);

@DataGetAiDay("Tag-name",int Data-Type,year,mon,day);

@DataGetAiMon("Tag-name",int Data-Type,year,mon);

@DataGetAiYear("Tag-name",int Data-Type,year);

@DataGetDiMin("Tag-name",int Data-Type,year,mon,day,hour,min);

@DataGetDiHour("Tag-name",int Data-Type,year,mon,day,hour);

@DataGetDiDay("Tag-name",int Data-Type,year,mon,day);

@DataGetDiMon("Tag-name",int Data-Type,year,mon);

@DataGetDiYear("Tag-name",int Data-Type,year);

 

The above function is a script that fetches stored data values in minutes/hour/day/month/year.

Data-Type

For analog input tags, 0: average, 1: minimum, 2: maximum, 3: integrated, 4: current maximum- past maximum

For digital input tag, 0:ON time, 1:OFF time, 2: ON/OFF count

 

2)-1  Write YEAR, MON, DAY, HOUR and MIN to memory tags of anlaog tag

Create an analog memory tag to store the next data to be imported.

(For example, to view the 'hour data' for AI_0001 and AI_0002 data, a memory tag is created to store it. DATAAI_01, DATAAI02)

 

 

2)-2  As shown in the picture above, on the localmain, a screen for setting a time and a screen for viewing data at a set time are composed.

Write a script that can change the year/month/day/hour as shown in the following figure in 1) above, at the screen for setting a time.

In order for the user to change the month/day/hour, first, make six script buttons. (Month +/- button, day +/- button, time +/- button)

 

Write a script on each button as shown in the following figure.

 

 

@TimePlusHour($YEAR,$MON,$DAY,$HOUR); // Time +  button script

 

for(i=1  ; i <=2  ; i = i+1 ){

   @sprintf(buf,"AI_%04d",i ) ;           // Store ˇ°AI_0001ˇ±and ˇ°AI_0002ˇ± into buffer whose name is buf. They are analog input tag.

   @sprintf(buf1,"DATAAI_%02d",i ) ;    // Store ˇ°DATAAI_01ˇ± and ˇ°DATAAI_02ˇ±into buffer whose name is buf1.

    

   value=@DataGetAiHour(buf,4,$YEAR,$MON,$DAY,$HOUR);  // Store (max of current - max of previous) of the corresponing year/month/day/hour of the tag stored in the buf into variable called value.

   @SetTagValue(buf1,value);    // Store the value into buf1 (DATAAI_01/02).

}

 

Write the script at each 6 script button like script above.